package com.yanqu.road.server.cmd.activity.rank;

import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.pb.activity.CrossActivityRankProto;
import com.yanqu.road.pb.cookboyactivity.CookBoyActivityProto;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.relation.CrossRelationRankMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = CrossProtocol.C2_CROSS_GET_RELATION_ACTIVITY_RANK,desc = "小当家活动榜单")
public class GetCrossRelationActivityRankListCmd extends CrossCommand {
    private long userId;
    private int activityId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossActivityRankProto.CrossActivityRankReqMsg reqMsg = CrossActivityRankProto.CrossActivityRankReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossActivityRankListModel rankListModel = CrossRelationRankMgr.getCrossActivityRankListModel(activityId);
        CookBoyActivityProto.CookBoyActivityRankListRespMsg.Builder respMsg = CookBoyActivityProto.CookBoyActivityRankListRespMsg.newBuilder();
        RankProto.RankListMsg.Builder rankListMsg = RankProto.RankListMsg.newBuilder();
        respMsg.setMyRank(-1);
        if (rankListModel != null) {
            rankListMsg = rankListModel.getRankListMsg();
            respMsg.setMyRank(rankListModel.getMyRank(userId, serverId));
        }
        respMsg.setRankList(rankListMsg);
        YanQuMessage message = YanQuMessageUtils.buildMessage(Protocol.U_COOK_BOY_ACTIVITY_RANK, respMsg);
        MessageHelper.sendPacket(serverId, userId, message);
    }

    @Override
    public void sendData() {

    }
}
